<?php

namespace app\common\library;

use Webman\RedisQueue\Redis;

class QueueRedis
{
    public static function now($job, $data = [], $connection = 'webman_gii', $addJobId = false)
    {
        if ($addJobId) {
            $data['job_id'] = Str::generate_str(16, 2);
        }
        if (Redis::connection($connection)->send($job, $data)) {
            return $data['job_id'] ?? true;
        }
        return false;
    }

    public static function delay($job, $delay, $data = [], $connection = 'webman_gii', $addJobId = false)
    {
        if ($addJobId) {
            $data['job_id'] = Str::generate_str(16, 2);
        }
        if (Redis::connection($connection)->send($job, $data, $delay)) {
            return $data['job_id'] ?? true;
        }
        return false;
    }
}